/**
 * @description 数据参数校验中间件
 * @author 盘古他爹
 */
const Joi = require('joi')
import { userLogin, like_list_one,like_list_one_del } from "../config/schema.confit"
import ResponseModel from "../config/response.config"
 class Validator {

  /**
   * 用户登录，注册校验
   * @param ctx ctx
   * @returns 
   */
  async  userLoginRegisterSchema(ctx: any, next: any) {
        try {
            const res = await userLogin.validateAsync(ctx.request.body);
            await next()
            // return res
        }
        catch (err) {
            console.error(err.message);
           ctx.body = ResponseModel.error({msg: err.message})
         }
    }


/**
 * list数据校验
 * @param ctx 
 * @param next 
 */
 async likeListOneSchema(ctx: any, next: any) {

    try {
        const res = await like_list_one.validateAsync(ctx.request.body);
        await next()
    } catch (err) {
        console.error("验证错误", err);
        
        ctx.body = ResponseModel.error({msg: err.message})
    }

 }

 async likeListOneDelSchema(ctx: any, next: any) {

    try{
       const res = await like_list_one_del.validateAsync(ctx.request.body)
       console.log("res", res);
       
        await next()
    } catch (err) {
        ctx.body = ResponseModel.error({msg: err.message})
    }

 }

}

export default new Validator()